package com.sailor.exception;

import com.sailor.common.CommonResponse;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {
    /**
     * 权限异常
     */
    @ExceptionHandler({UnauthorizedException.class, AuthorizationException.class})
    public String authorizationException(Exception e) {
        System.out.println("授权异常");
        return "授权异常";
    }

    /**
     * 统一的异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public CommonResponse handleException(Exception e) {
        System.out.println(e);
        return CommonResponse.builder().message(e.getMessage()).resultCode(1).build();
    }
}
